package com.example.com.skills_utf8;

import java.util.Locale;

import com.utils.Utils1;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class _50Activity extends Activity {

	_50Activity activity = this;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_50);
		
		Button btn_lanuage_chinese = (Button)findViewById(R.id.btn_lanuage_chinese);
		Button btn_lanuage_english = (Button)findViewById(R.id.btn_lanuage_english);
		
		
		btn_lanuage_chinese.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				Utils1.showLoadingDialog(activity, getResources().getString(R.string.changing));
				Handler handler = new Handler();
				handler.postDelayed(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						
						Utils1.dismissLoadingDialog();
						setLanguage(0);
						
					}
				}, 2000);
				
				
			}
		});
		
		btn_lanuage_english.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				Utils1.showLoadingDialog(activity, getResources().getString(R.string.changing));
				Handler handler = new Handler();
				handler.postDelayed(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						
						Utils1.dismissLoadingDialog();
						setLanguage(2);
						
					}
				}, 2000);
			}
		});
		
		
		
		
		

	}

	private void setLanguage(int i) {


		Configuration config = new Configuration();
		switch (i) {
		case 0:
			Locale.setDefault(Locale.SIMPLIFIED_CHINESE);
			config.locale = Locale.SIMPLIFIED_CHINESE;
			break;
		case 1:
			Locale.setDefault(Locale.TRADITIONAL_CHINESE);
			config.locale = Locale.TRADITIONAL_CHINESE;
			break;
		case 2:
			Locale.setDefault(Locale.ENGLISH);
			config.locale = Locale.ENGLISH;
			break;
		}
		getBaseContext().getResources().updateConfiguration(config, null); // 存储最新更新的配置
		updateActivity();

	}

	private void updateActivity() {
		Intent intent = new Intent();
		intent.setClass(this, _50Activity.class);// 当前Activity重新打开
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		this.finish();
		this.startActivity(intent);

	}
	

}



